package cn.usian.controller;

import cn.usian.common.R;
import cn.usian.entity.SetmealDTO;
import cn.usian.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping("setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @GetMapping("page")
    public R findPage(Integer page,Integer pageSize,String name){
        return setmealService.findPage(page,pageSize,name);
    }

    @DeleteMapping
    public R delSetmeal(Long[] ids){
        return setmealService.delSetmeal(ids);
    }

    @PostMapping("status/{status}")
    public R updateone(Long[] ids,@PathVariable("status") Integer status){
        setmealService.updateone(ids,status);
        return  R.success("状态修改成功");
    }

    @PostMapping
    public R addSetmeal(@RequestBody SetmealDTO setmealDTO, HttpServletRequest request){
        Long id=(Long)request.getSession().getAttribute("employee");
        setmealDTO.setCreateUser(id);
        setmealDTO.setUpdateUser(id);
        setmealService.addSetmeal(setmealDTO,id);
        return R.success("添加成功");
    }

}
